package com.ruoyi.duty.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.duty.domain.DutyCheck;
import com.ruoyi.duty.service.IDutyCheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查岗记录Controller
 * 
 * @author yepanpan
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/duty/check")
public class DutyCheckController extends BaseController
{
    @Autowired
    private IDutyCheckService dutyCheckService;

    /**
     * 查询查岗记录列表
     */
    @PreAuthorize("@ss.hasPermi('duty:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyCheck dutyCheck)
    {
        startPage();
        List<DutyCheck> list = dutyCheckService.selectDutyCheckList(dutyCheck);
        return getDataTable(list);
    }

    /**
     * 导出查岗记录列表
     */
    @PreAuthorize("@ss.hasPermi('duty:check:export')")
    @Log(title = "查岗记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DutyCheck dutyCheck)
    {
        List<DutyCheck> list = dutyCheckService.selectDutyCheckList(dutyCheck);
        ExcelUtil<DutyCheck> util = new ExcelUtil<DutyCheck>(DutyCheck.class);
        util.exportExcel(response, list, "查岗记录数据");
    }


    /**
     * 获取查岗记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('duty:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dutyCheckService.selectDutyCheckById(id));
    }

    /**
     * 新增查岗记录
     */
    @PreAuthorize("@ss.hasPermi('duty:check:add')")
    @Log(title = "查岗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DutyCheck dutyCheck)
    {
                dutyCheck.setCreateBy(getUsername());
        return toAjax(dutyCheckService.insertDutyCheck(dutyCheck));
    }

    /**
     * 修改查岗记录
     */
    @PreAuthorize("@ss.hasPermi('duty:check:edit')")
    @Log(title = "查岗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DutyCheck dutyCheck)
    {
                dutyCheck.setUpdateBy(getUsername());
        return toAjax(dutyCheckService.updateDutyCheck(dutyCheck));
    }

    /**
     * 删除查岗记录
     */
    @PreAuthorize("@ss.hasPermi('duty:check:remove')")
    @Log(title = "查岗记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dutyCheckService.deleteDutyCheckByIds(ids));
    }
}
